<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/admin/commons/taglib.jsp"%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>后台管理</title>
    <s:include value="/layouts/datePicker.jsp"></s:include>
    <script type="text/javascript">
        $(function(){
            $("#lesson").addClass("active");
            $("#lesson").find("ul li").eq(1).addClass("active");
        })
    </script>
</head>
<body>
    <div class="admin">
        <div class="panel">
            <div class="panel-head"><strong>添加班级</strong></div>
            <div class="panel-body">
                <form action="lesson!save.action" id="form" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="lesson.id" value="${lesson.id}"/>
                    <input id="twoClassifyId" type="hidden" value="${lesson.twoClassifyId}"/>
                    <div class="form-group">
                        <div class="label"><label for="teacher">选择教师</label></div>
                        <div class="field">
                            <select id="teacher" class="border radius" style="width:100%;height:35px;"  name="lesson.teacherName">
                                <s:iterator value="teacherList">
                                    <option value="<s:property value="id"/>-<s:property value="name"/>"
                                     <s:if test="id==lesson.teacherId">selected="selected"</s:if>><s:property value="name"/></option>
                                </s:iterator>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label"><label for="classifyType">课程分类</label></div>
                        <div class="field" style="width: 49.5%;float: left;">
                            <select id="classifyType" class="border radius" style="width:100%;height:35px;"  name="lesson.oneClassifyName"
                                onchange="findClassifySon()">
                                <s:iterator value="classifyList">
                                    <option value="<s:property value="id"/>-<s:property value="name"/>"
                                      <s:if test="id==lesson.oneClassifyId">selected="selected"</s:if>><s:property value="name"/></option>
                                </s:iterator>
                            </select>
                        </div>
                        <div class="field" style="width: 49.5%;float: left;margin-left: 1%;" >
                            <select id="classifyType2" class="border radius" style="width:100%;height:35px;" name="lesson.twoClassifyName">

                            </select>
                        </div>
                    </div>
                    <div style="clear: both;height: 5px;"></div>
                    <div class="form-group">
                        <div class="label"><label >班级人数</label></div>
                        <div class="field">
                            <input type="number" class="input"  name="lesson.stuNum" size="50" placeholder="请输入班级人数"
                                   data-validate="required:请输入班级人数,int:必须为数字" value="${lesson.stuNum}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label"><label for="weekDate">选择上课时间</label></div>
                        <div class="field" style="width: 49.5%;float: left;">
                            <select id="weekDate" class="border radius" style="width:100%;height:35px;"  name="lesson.weekDate">
                                <option value="周一" <s:if test="'周一'==lesson.weekDate">selected="selected"</s:if>>周一</option>
                                <option value="周二" <s:if test="'周二'==lesson.weekDate">selected="selected"</s:if>>周二</option>
                                <option value="周三" <s:if test="'周三'==lesson.weekDate">selected="selected"</s:if>>周三</option>
                                <option value="周四" <s:if test="'周四'==lesson.weekDate">selected="selected"</s:if>>周四</option>
                                <option value="周五" <s:if test="'周五'==lesson.weekDate">selected="selected"</s:if>>周五</option>
                                <option value="周六" <s:if test="'周六'==lesson.weekDate">selected="selected"</s:if>>周六</option>
                                <option value="周日" <s:if test="'周日'==lesson.weekDate">selected="selected"</s:if>>周日</option>
                            </select>
                        </div>
                        <div class="field" style="width: 24%;float: left;margin-left: 1%;">
                            <input name="lesson.startTime" id="startTime" type="text" class="input" placeholder="上课开始时间"
                                   onFocus="WdatePicker({dateFmt:'HH:mm',maxDate:'#F{$dp.$D(\'endTime\')}'})"
                                value="${lesson.startTime}"/>
                        </div>
                        <div class="field" style="width: 24.5%;float: left;margin-left: 1%;">
                            <input name="lesson.endTime" id="endTime" type="text" class="input" placeholder="上课结束时间"
                                   onFocus="WdatePicker({dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'startTime\')}',maxDate:'%y-%M-%d %H:%m:%s'})"
                                value="${lesson.endTime}"/>
                        </div>
                    </div>
                    <div style="clear: both;height: 5px;"></div>
                    <div class="form-group">
                        <div class="label"><label >开课时间</label></div>
                        <div class="field">
                            <input name="lesson.startDate"  type="text" class="input" placeholder="开课时间"
                                   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"
                                   value="${lesson.startDate}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label"><label >学习周长</label></div>
                        <div class="field">
                            <input type="number" class="input"  name="lesson.studyWeekNum" size="50" placeholder="请输入周数"
                                   data-validate="required:请输入周数,int:必须为数字" value="${lesson.studyWeekNum}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label"><label >上课地址</label></div>
                        <div class="field">
                            <input type="number" class="input"  name="lesson.address" size="50" placeholder="请输入上课地址"
                                   data-validate="required:请输入上课地址" value="${lesson.address}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label"><label >学费</label></div>
                        <div class="field">
                            <input type="number" class="input"  name="lesson.price" size="50" placeholder="请输入班级学费"
                                   data-validate="required:请输入班级人数,double:必须为数字" value="${lesson.price}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label"><label>热门班级</label></div>
                        <div class="field">
                            <input type="radio" name="lesson.isHot" class="radioSize" value="0" <s:if test="1!=lesson.isHot">checked="checked"</s:if>/>否
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="lesson.isHot" class="radioSize" value="1" <s:if test="1==lesson.isHot">checked="checked"</s:if>/>是
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label"><label >课程简介</label></div>
                        <div class="field">
                            <textarea id="teacherDesc" name="lesson.content" class="input" rows="4" cols="5" style="resize: none"
                                      placeholder="请输入课程简介">${lesson.content}</textarea>
                        </div>
                    </div>

                    <div style="clear: both;height: 5px;"></div>
                    <button class="button bg-blue" onclick="return checkForm()">提交</button>
                </form>
            </div>
        </div>
    </div>
    <script>
        //初始化二级分类
        findClassifySon();
        function findClassifySon(){
            var twoClassifyId = $('#twoClassifyId').val();
            var parent_id = $('#classifyType option:selected').val().split("-")[0];
            $.ajax({
                'url':'classify!findSonClassify.action',
                'type':'post',
                'data':{'classify.parentId':parent_id},
                'dataType':'json',
                'success':function(data){
                    $('#classifyType2').html("");
                    var select = document.getElementById("classifyType2");
                    for(var i=0;i<data.length;i++){
                        var classify = data[i];
                        var value = classify.id+"-"+classify.name;
                        console.log(twoClassifyId+","+classify.id);
                        if(twoClassifyId*1==classify.id){
                            var option = new Option(classify.name,value,true,true);
                        }else {
                            var option = new Option(classify.name,value);
                        }

                        select.options.add(option);
                    }
                },
                'error':function(){
                    alertDiv("请求失败！");
                }
            });
        }
    </script>
</body>
</html>

